#ifndef INSPECTOR_H
#define INSPECTOR_H

#include "dict.h"
#include "list.h"
#include "redismodule.h"
#include "skiplist.h"

#define REDISMODULE_KEYTYPE_MODULE_TAIR_STRING 1000
#define REDISMODULE_KEYTYPE_MODULE_TAIR_HASH 1001

#define Module_Assert(_e) ((_e) ? (void)0 : (_moduleAssert(#_e, __FILE__, __LINE__), abort()))

#define REDISMODULE_API_FUNC(x) (*x)
extern void *REDISMODULE_API_FUNC(RedisModule_Alloc)(size_t bytes);
extern void *REDISMODULE_API_FUNC(RedisModule_Realloc)(void *ptr, size_t bytes);
extern void REDISMODULE_API_FUNC(RedisModule_Free)(void *ptr);
extern void *REDISMODULE_API_FUNC(RedisModule_Calloc)(size_t nmemb, size_t size);

#define zfree RedisModule_Free
#define zmalloc RedisModule_Alloc
#define zcalloc(x) RedisModule_Calloc(1, x)

typedef struct TaskConfig {
    uint32_t enable;
    uint32_t exclusive;
    uint32_t interval;
    uint32_t scan_tick;
    uint32_t scan_count;
    uint32_t items_threshold;
    uint64_t memory_threshold;
    uint32_t ttl_threshold;
} TaskConfig;

typedef struct TaskInfo {
    RedisModuleTimerID timer_id;
    uint32_t is_running;

    uint64_t start_time;
    uint64_t cost_time;

    uint64_t dbsize;
    uint32_t count;

    // RedisModuleString* <--> SystemUsage*
    dict *sys_data;
    m_zskiplist *global_big_key;
} TaskInfo;

typedef struct SystemUsage {
    uint64_t capacity;
    uint32_t key_cnt;
    uint32_t key_cnt_string;
    uint32_t key_cnt_list;
    uint32_t key_cnt_hash;
    uint32_t key_cnt_set;
    uint32_t key_cnt_zset;
    uint32_t key_cnt_tair_string;
    uint32_t key_cnt_tair_hash;
    uint32_t key_cnt_other;

    uint32_t big_key_cnt;
    uint64_t big_key_capacity;
    m_zskiplist *big_key_sample;

    uint32_t ttl_key_cnt;
    uint64_t ttl_key_capacity;
    list *ttl_key_sample;  // RedisModuleString*
} SystemUsage;

#endif
